//
//  Util.m
//  HYTest
//
//  Created by 刘林欣 on 16/7/23.
//  Copyright © 2016年 刘林欣. All rights reserved.
//

#import "Util.h"

@implementation Util

+ (float)curSysVersion{
    return [UIDevice currentDevice].systemVersion.floatValue;
}

+ (UIWindow*)getWindow{
    return [[UIApplication sharedApplication].delegate window];
}

+ (UIViewController*)getRootViewController{
    return [self getWindow].rootViewController;
}

+ (UIAlertController*)showNewAlert:(NSString*)title content:(NSString*)content okHandler:(void (^ __nullable)(UIAlertAction *action))okHandler cancelHandler:(void (^ __nullable)(UIAlertAction *action))cancelHandler{
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:title message:content preferredStyle:UIAlertControllerStyleAlert];
    if(okHandler){
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:okHandler];
        [alertC addAction:okAction];
    }
    if(cancelHandler){
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:cancelHandler];
        [alertC addAction:cancelAction];
    }
    [[self getRootViewController] presentViewController:alertC animated:YES completion:^(){}];
    
    return alertC;
}

@end
